﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Task.BLL;
using Yipusoft.Task.Model;
using Yipusoft.Evaluate.BLL;
using Yipusoft.Evaluate.Model;
using System.Collections.Generic;


public partial class Evaluate_BaseNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, "320301"))
        {
            Response.Write("<script>alert('没有权限！');history.back(0);</script>");
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["BaseID"] == null)
            {
                ActionTitle.Text = "添加基础数据项目";
            }
            else
            {
                ActionTitle.Text = "编辑基础数据项目";
                BindData();
            }
        }
    }
    private void BindData()
    {
        BaseInfo bases = Base.GetBase(int.Parse(Request.QueryString["BaseID"]));
        BaseName.Text = bases.BaseName;
        TotalScore.Text = bases.TotalScore.ToString("#");
        Description.Text = bases.Description;
    }
    private void Insert()
    {
        BaseInfo bases = new BaseInfo();
        bases.BaseName = BaseName.Text;
        bases.TotalScore = decimal.Parse(TotalScore.Text);
        bases.Description = Description.Text;
        bases.DepartmetnID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 6) + "0";
        bases.UnitID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        bases.Flag = 0;
        int BaseID = Base.Insert(bases);

        EventLogInfo log = new EventLogInfo();
        log.EventTime = DateTime.Now;
        log.EventType = 1;
        log.EventData = "添加基础数据项目";
        log.ItemID = BaseID.ToString();
        log.ItemName = "Base";
        log.ItemFullUrl = "BaseNew.aspx";
        log.CreatedBy = Context.User.Identity.Name;
        log.CreatedTime = DateTime.Now;
        log.UserIP = Request.UserHostAddress;
        EventLog.Insert(log);

        Prompt.Text = "提示：添加成功！";
    }
    private void Update()
    {
        BaseInfo bases = Base.GetBase(int.Parse(Request.QueryString["BaseID"]));
        bases.BaseName = BaseName.Text;
        bases.TotalScore = decimal.Parse(TotalScore.Text);
        bases.Description = Description.Text;
        bases.UnitID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        bases.Flag = 0;
        Base.Update(bases);

        EventLogInfo log = new EventLogInfo();
        log.EventTime = DateTime.Now;
        log.EventType = 1;
        log.EventData = "更新基础数据项目";
        log.ItemID = Request.QueryString["BaseID"];
        log.ItemName = "Base";
        log.ItemFullUrl = "BaseNew.aspx";
        log.CreatedBy = Context.User.Identity.Name;
        log.CreatedTime = DateTime.Now;
        log.UserIP = Request.UserHostAddress;
        EventLog.Insert(log);

        Prompt.Text = "提示：更新成功！";
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["BaseID"] == null)
                Insert();
            else
                Update();
        }
        catch (Exception ex)
        {
            Prompt.Text = "错误：" + ex.Message;
        }
    }
}
